package com.sptpc.learnspring.repository;

import com.sptpc.learnspring.model.Drink;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DrinkRepository extends JpaRepository<Drink, Long> {
    List<Drink> findDrinksByNameLike(String key);
    List<Drink> findDrinksByCategory_Id(Long cid);
    List<Drink> findDistinctByIdIn(List<Long> ids);

    // HQL
    @Query("select new com.sptpc.learnspring.model.Drink(d.name, d.price, c.name) " +
            "FROM Drink d LEFT JOIN com.sptpc.learnspring.model.Category c " +
            "ON d.category=c.id " +
            "WHERE d.id=:did")
    Drink findDrinkById2(@Param("did") Long id);
}
